package mulegame;

import static org.junit.Assert.*;
import java.awt.Color;
import org.junit.Test;

public class GameEngineTest {

	// tests the storeSellTo() method in GameEngine when the player successfully purchases from the Store
	// tests whether method returns True
	@Test
	public void testStoreSellToSuccessful(){
		GameEngine engine = new GameEngine();
		engine.setDifficulty(GameConfig.Difficulty.BEGINNER);
		engine.setNumPlayers(2);
		engine.setTurn(0);
		engine.makePlayer("Jim", Player.Race.CARIBOUER, Color.black);
		engine.setTurn(1);
		engine.makePlayer("Pete", Player.Race.CARIBOUER, Color.green);
		
		engine.setTurn(0);
		
		assertTrue("should return True", engine.storeSellTo(Store.ItemType.FOOD, 3));
		
	}
	
	
	// tests the storeSellTo() method in GameEngine when the player fails to purchase from the Store
	// tests whether method returns False
	@Test
	public void testStoreSellToFailure(){
		GameEngine engine = new GameEngine();
		engine.setDifficulty(GameConfig.Difficulty.BEGINNER);
		engine.setNumPlayers(2);
		engine.setTurn(0);
		engine.makePlayer("Jim", Player.Race.CARIBOUER, Color.black);
		engine.setTurn(1);
		engine.makePlayer("Pete", Player.Race.CARIBOUER, Color.green);
		
		engine.setTurn(0);
		
		engine.getCurrPlayer().setMoney(0);
		
		assertFalse("should return False", engine.storeSellTo(Store.ItemType.FOOD, 3));
		
	}
	
	
	// tests the sortPlayers() method in GameEngine
	// tests if order of Player names is the same as expected
	@Test
	public void testSortPlayers() {
		
		GameEngine engine = new GameEngine();
		engine.setNumPlayers(4);
		engine.setTurn(0);
		engine.makePlayer("Jim", Player.Race.CARIBOUER, Color.black);
		engine.setTurn(1);
		engine.makePlayer("Pete", Player.Race.CARIBOUER, Color.green);
		engine.setTurn(2);
		engine.makePlayer("Sally", Player.Race.CARIBOUER, Color.blue);
		engine.setTurn(3);
		engine.makePlayer("Jill", Player.Race.CARIBOUER, Color.yellow);
		
		engine.getPlayer(0).setFood(3);
		engine.getPlayer(1).setFood(2);
		engine.getPlayer(2).setFood(1);
		engine.getPlayer(3).setFood(0);
		
		engine.sortPlayers();
		
		Player[] p = engine.getPlayers();
		
		String expectedOrder = "Jill,Sally,Pete,Jim";
		String actualOrder = p[0].getName()+","+p[1].getName()+","+p[2].getName()+","+p[3].getName();
		
		assertEquals("The order of players should match", expectedOrder, actualOrder);

	}
}
